// 泛型
interface A<T> {
    name: T    //不确定name的类型
}
let a: A<string> = {
    name: '张三'
}
let b: A<boolean> = {
    name: true
}



//泛型工具
/*interface Props {
    name: string,
    age: number,
}
let c: Props = {
    name: '张三',
    age: 10
}*/


// 1.Partial 把 Props所有属性改变为可选  相当于？
/*interface Props {
    name: string,
    // age: number,
}

/!*let c: Partial<Props> = {
    name: '张三',
    age: 10
}*!/

type m=Partial<Props>
let c: m = {
    name: '张三',
    age: 10
}*/


// 2.Readonly 把 Props所有属性改变为只读
/*interface Props {
    name: string,
    age: number,
}
let c: Readonly<Props> = {
    name: '张三',
    age: 10
}
// c.name = ''    //报错，只读不可改*/


// 3.Pick<Type,Keys> 从Type 中选择属性来构建新的类型 注意：第二个参数一定要在第一个参数中有
/*interface Props {
    name: string,
    age: number,
    sex:string
}
let c: Pick<Props, 'age' | 'name' | 'sex'> = {
    age: 20,
    name: '',
    sex: ''
}*/


// 4.Record<Keys，Type> 构造一个对象类型，属性键为Keys, 属性类型为 Type
interface Props {
    name: string,
    age: number,
    sex:string
}
type R = Record<'name' | 'age', string>
// type R = { name: string, age: string }
let r: R = {
    name: '李四',
    age: ''
}